<?php
namespace Curl;

trait InitCurl
{
    public $curlConfigOption;

    public function __construct()
    {
        $this->curlConfigOption = include "CurlOptionConfig.php";
    }

    /**
     * @Notes:设置配置选项
     * @User: chenping
     * @param string $config
     * @email: 375129701@qq.com
     */
    public function setConfig($config=[])
    {

        if(!empty($config) &&  is_array($config))
        {
            foreach ($config as $k=>$v)
            {
                $this->curlConfigOption[$k] = $v;
            }
        }
    }


    /**
     * @Notes: 生成 URL-encode 之后的请求字符串
     * @User: chenping
     * @email: 375129701@qq.com
     * @param array $param
     * @return string
     */
    public function httpBuildQuery($param=[])
    {
        $url = '' ;
        if($param && is_array($param))
        {
            $url =http_build_query($param);
        }
        return $url;
    }

    /**
     * @Notes: 解析 URL，返回其组成部分
     * @User: chenping
     * @email: 375129701@qq.com
     * @param $url
     * @return array|mixed
     */
    public function httpParseUrl($url)
    {
        $new_url=[];
        if($url)
        {
            $new_url =  parse_url($url);
        }
        return $new_url;
    }

}